import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/utils/toast_util.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_underline_button.dart';
import 'package:kq_flutter_widgets/widgets/floating/KqFloatingView.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

import '../../resources/Images.dart';

/// 悬浮控件演示
class FloatingViewDemoPage extends StatefulWidget {
  const FloatingViewDemoPage({Key? key}) : super(key: key);

  @override
  FloatingViewDemoPageState createState() => FloatingViewDemoPageState();
}

class FloatingViewDemoPageState extends State<FloatingViewDemoPage> {
  bool showFloating = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '悬浮控件演示',
      ),
      body: KqFloatingView(
        left: 0,
        top: 200.r,
        floatingWidgetBuilder: showFloating
            ? (left, top, isLeft, isDragging) {
          return Container(
            color: Colors.blue,
            padding: const EdgeInsets.all(8.0),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                if (isLeft && !isDragging)
                  KqInkWell(
                    onTap: () {
                      setState(() {
                        showFloating = false;
                      });
                    },
                    child: Image.asset(
                      Images.demoIcClose16Line,
                      width: 30.r,
                      height: 30.r,
                    ),
                  ),
                if (isLeft && !isDragging)
                  SizedBox(
                    width: 10.r,
                  ),
                KqUnderlineButton(
                  title: '测试悬浮窗口',
                  onTap: () {
                    KqToast.showNormal('测试点击');
                  },
                ),
                if (!isLeft && !isDragging)
                  SizedBox(
                    width: 10.r,
                  ),
                if (!isLeft && !isDragging)
                  KqInkWell(
                    onTap: () {
                      setState(() {
                        showFloating = false;
                      });
                    },
                    child: Image.asset(
                      Images.demoIcClose16Line,
                      width: 30.r,
                      height: 30.r,
                    ),
                  ),
              ],
            ),
          );
        }
            : null,
        child: Column(
          children: [
            Expanded(
                child: Container(
                  color: Colors.red,
                ))
          ],
        ),
      ),
    );
  }
}
